home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / fig2eng / fig2eng.c < prev    next >
C/C++ Source or Header  |  1994-06-26  |  30KB  |  1,315 lines

  1. /* fig2eng.c -- version 0.4 -- 21:29 GMT +10  Mon 27 June 1994.
  2.  *
  3.  *  fig2eng -- Convert Fig 2.1 code numbers to English.
  4.  *
  5.  *  Geoffrey Tobin
  6.  *  ecsgrt@luxor.latrobe.edu.au
  7.  *
  8.  *  Version History:
  9.  *
  10.  *  0.0 -- initial attempt, working from Fig2MF 0.04 gt mod 1x.
  11.  *
  12.  *  0.1 -- fix for arrows in splines.  (fa, ba were wrongly read as
  13.  *         floats.)
  14.  *      -- EPS line, if present, must _precede_ the points line.
  15.  *         (This is contrary to both the Transfig Manual, 2.1.8, and
  16.  *         xfig/Doc/FORMAT2.1 file for xfig 2.1.8, but it is what the
  17.  *         `readme.c' file in transfig 2.1.8 does, so!)
  18.  *
  19.  *  0.2 -- count objects from 1, not 0 as before.
  20.  *
  21.  *  0.3 -- state arrow direction before detailed arrow information.
  22.  *      -- tabs in this C source replaced by spaces.
  23.  *
  24.  *  0.4 -- fig2eng.c has prototypes, and detects ANSI (or non-ANSI) C
  25.  *         compiler.
  26.  */
  27.  
  28. #include <stdio.h>
  29.  
  30.  
  31. #define OUTPUT      printf
  32.  
  33. #define put_msg(x)  fputs (x, stderr); \
  34.   fprintf (stderr, \
  35.   " in file \"%s\" \n", figfile)
  36.  
  37. #define dofill()  (1.2 - ((double) area_fill / (double) FILL_BLACK))
  38.  
  39. #define dopen(x)  (((x-1)*PEN_INCR) + DEF_PEN)
  40.  
  41. #define FIG_HEADER_LEN  8
  42. #define TITLE           "fig2eng"
  43. #define VERSION         "0.4  Mon 27 June 1994"
  44. #define BUF_SIZE        1024
  45. #define O_ELLIPSE       1
  46. #define O_POLYLINE      2
  47. #define O_SPLINE        3
  48. #define O_TEXT          4
  49. #define O_ARC           5
  50. #define O_COMP          6
  51. #define O_ECOMP       (-6)
  52. #define FILL_BLACK      21
  53. #define N_CURVE         11
  54. #define N_POLYLINE      12
  55. #define N_ELLIPSE       19
  56. #define N_ARC           20
  57. #define DEF_PEN         0.5
  58. #define PEN_INCR        0.10
  59.  
  60.  
  61. char *progname = "";
  62. char *figfile = "";
  63.  
  64. int ppi;
  65.  
  66.  
  67. #define OK     0
  68. #define FAIL (-1)
  69.  
  70.  
  71. /* Function prototypes */
  72.  
  73. #ifdef __STDC__
  74. #define __(X) X
  75. #define Void void
  76. #else
  77. #define __(X) ()
  78. #define Void int
  79. #endif
  80.  
  81. int main __((int argc, char * argv[]));
  82. int skipspaces __((FILE * fp));
  83. int process __((char * filename));
  84. int compound __((FILE * fp));
  85. Void end_compound __((void));
  86. int common_fields __((FILE * fp));
  87. int arrow __((FILE * fp));
  88. int points __((FILE * fp, int * p_npts));
  89. int arrow_check __((int fa, int ba));
  90. int polyline __((FILE * fp));
  91. int spline __((FILE * fp));
  92. int ellipse __((FILE * fp));
  93. int arc __((FILE * fp));
  94. int text __((FILE * fp));
  95.  
  96.  
  97. /* Function code */
  98.  
  99. int
  100. main
  101. #ifdef __STDC__
  102.   (int argc, char * argv[])
  103. #else
  104.   (argc, argv)
  105.     int  argc;
  106.     char * argv[];
  107. #endif
  108. {
  109.     FILE * fp;
  110.     int i;
  111.  
  112.     progname = argv[0];
  113.     figfile = "Standard Input";
  114.  
  115.     OUTPUT ("%%\n%% %s:  %s version %s \n%%\n",
  116.         progname, TITLE, VERSION);
  117.  
  118.     if (argc < 2)
  119.         process ("-");
  120.     else
  121.     {
  122.         for (i=1; i < argc; i++)
  123.             process (argv[i]);
  124.     }
  125.  
  126.     return (0);
  127. } /* main */
  128.  
  129.  
  130. int
  131. skipspaces
  132. #ifdef __STDC__
  133.   (fp)
  134.     FILE * fp;
  135. #else
  136.   (FILE * fp)
  137. #endif
  138. {
  139.     int ch;
  140.     while (((ch = getc (fp)) != EOF || !feof (fp)) && isspace (ch))
  141.         ;
  142.     /* if not at end of file, ch is now a nonspace */
  143.     if (ch != EOF || !feof (fp))
  144.     {
  145.         if (ungetc (ch, fp) == EOF)
  146.         {
  147.             put_msg ("FATAL ERROR:  ungetc failed!");
  148.             OUTPUT ("FATAL ERROR:  ungetc failed\n");
  149.             return FAIL;
  150.         }
  151.     }
  152. } /* skipspaces */
  153.  
  154. int
  155. process
  156. #ifdef __STDC__
  157.   (char * filename)
  158. #else
  159.   (filename)
  160.     char * filename;
  161. #endif
  162. {
  163.     int status = OK;
  164.     FILE * fp = (FILE *) NULL;
  165.     int ch;
  166.     char tmpbuf[FIG_HEADER_LEN+2];  /* possible newline, plus ascii nul */
  167.     int nobjs = 0;  /* counts objects in Fig file */
  168.     int coord_sys;
  169.     int object;
  170.  
  171.     if (filename[0] == '-')
  172.     {
  173.         figfile = "Standard Input";
  174.         fp = stdin;
  175.     }
  176.     else
  177.     {
  178.         figfile=filename;
  179.         if ((fp = fopen (filename, "r")) == NULL)
  180.         {
  181.             fprintf (stderr,
  182.                 "%s: cannot open the input file \"%s\"\n",
  183.                 progname, filename);
  184.             status = FAIL;
  185.             goto LabelFail;
  186.         }
  187.     }
  188.  
  189.     /* gt - input Fig file */
  190.  
  191.     OUTPUT ("\n");
  192.     OUTPUT ("%% Interpreting Fig file:\n");
  193.     OUTPUT ("%% \n");
  194.     OUTPUT ("%% `%s' \n", figfile);
  195.     OUTPUT ("\n");
  196.  
  197.     fgets (tmpbuf, sizeof (tmpbuf), fp);
  198.  
  199.     if (strncmp (tmpbuf, "#FIG 2.1", FIG_HEADER_LEN) != 0)
  200.     {
  201.         put_msg ("Header is not the expected `#FIG 2.1'!");
  202.         OUTPUT ("Header is `%s', but expected `#FIG 2.1'\n", tmpbuf);
  203.         status = FAIL;
  204.         goto LabelFail;
  205.     }
  206.  
  207.     OUTPUT ("Fig 2.1\n");
  208.  
  209.     if (fscanf (fp, "%d%d", &ppi, &coord_sys) != 2)
  210.     {
  211.         put_msg ("INCOMPLETE ppi and coord_sys data!");
  212.         status = FAIL;
  213.         goto LabelFail;
  214.     }
  215.  
  216.     OUTPUT ("%d pixels per inch\n", ppi);
  217.  
  218.     switch (coord_sys)
  219.     {
  220.         case 1:   OUTPUT ("origin at lower left corner");  break;
  221.         case 2:   OUTPUT ("origin at upper left corner");  break;
  222.         default:
  223.               OUTPUT ("INVALID coordinate system");
  224.               put_msg ("INVALID coordinate system!");
  225.               status = FAIL;
  226.               goto LabelFail;
  227.               break;
  228.     }
  229.     OUTPUT ("\n");
  230.  
  231.     OUTPUT ("%% Note:  Numbering objects from 0.\n");
  232.  
  233.     for (nobjs = 0;  (ch = getc (fp)) != EOF || ! feof (fp);  nobjs++)
  234.     {
  235.         if (ungetc (ch, fp) == EOF)
  236.         {
  237.             put_msg ("FATAL ERROR:  ungetc failed!");
  238.             OUTPUT ("FATAL ERROR:  ungetc failed\n");
  239.             status = FAIL;
  240.             goto LabelFail;
  241.         }
  242.  
  243.         OUTPUT ("\n");  /* empty line before each object */
  244.         if (fscanf (fp, "%d", &object) != 1)
  245.         {
  246.             put_msg ("ERROR:  object needs to be an integer!");
  247.             OUTPUT ("ERROR:  object # %d needs to be an integer\n",
  248.                 nobjs+1);
  249.             status = FAIL;
  250.             goto LabelFail;
  251.         }
  252.  
  253.         OUTPUT ("Object # %d: \n", nobjs+1);
  254.         OUTPUT ("\n");
  255.         switch (object)
  256.         {
  257.             case O_ELLIPSE:
  258.                 if (ellipse (fp) == FAIL)
  259.                 {
  260.                     status = FAIL;
  261.                     goto LabelFail;
  262.                 }
  263.                 break;
  264.             case O_POLYLINE:
  265.                 if (polyline (fp) == FAIL)
  266.                 {
  267.                     status = FAIL;
  268.                     goto LabelFail;
  269.                 }
  270.                 break;
  271.             case O_SPLINE:
  272.                 if (spline (fp) == FAIL)
  273.                 {
  274.                     status = FAIL;
  275.                     goto LabelFail;
  276.                 }
  277.                 break;
  278.             case O_TEXT:
  279.                 if (text (fp) == FAIL)
  280.                 {
  281.                     status = FAIL;
  282.                     goto LabelFail;
  283.                 }
  284.                 break;
  285.             case O_ARC:
  286.                 if (arc (fp) == FAIL)
  287.                 {
  288.                     status = FAIL;
  289.                     goto LabelFail;
  290.                 }
  291.                 break;
  292.             case O_COMP:
  293.                 if (compound (fp) == FAIL)
  294.                 {
  295.                     status = FAIL;
  296.                     goto LabelFail;
  297.                 }
  298.                 break;
  299.             case O_ECOMP:
  300.                 end_compound ();
  301.                 break;
  302.             default:
  303.                 fprintf (stderr, "object (# %d) = %d is an ",
  304.                     nobjs+1, object);
  305.                 put_msg ("UNKNOWN object!");
  306.                 status = FAIL;
  307.                 goto LabelFail;
  308.                 break;
  309.         }
  310.         /* skip whitespaces, including end of line */
  311.         if (skipspaces (fp) == FAIL)
  312.         {
  313.             status = FAIL;
  314.             goto LabelFail;
  315.         }
  316.         if (object != O_COMP && object != O_ECOMP)
  317.         {
  318.             OUTPUT ("\n");
  319.             OUTPUT ("End of object # %d.\n", nobjs+1);
  320.         }
  321.     }
  322.  
  323.     if (fp != stdin)
  324.         fclose (fp);
  325.  
  326.     OUTPUT ("\n");
  327.     OUTPUT ("%% Finished reading Fig file `%s'. \n", figfile);
  328.     OUTPUT ("\n");
  329.  
  330.     return OK;
  331.  
  332. LabelFail:
  333.  
  334.     OUTPUT ("\n");
  335.     OUTPUT ("%% An Error interrupted reading Fig file `%s'. \n", figfile);
  336.     OUTPUT ("\n");
  337.  
  338.     return FAIL;
  339.  
  340. } /* process */
  341.  
  342.  
  343. int
  344. compound
  345. #ifdef __STDC__
  346.   (FILE * fp)
  347. #else
  348.   (fp)
  349.     FILE * fp;
  350. #endif
  351. {
  352.     int urx, ury;
  353.     int llx, lly;
  354.  
  355.     OUTPUT ("Compound Object:\n");
  356.  
  357.     fscanf (fp, "%d", &urx);
  358.     fscanf (fp, "%d", &ury);
  359.     fscanf (fp, "%d", &llx);
  360.     fscanf (fp, "%d", &lly);
  361.  
  362.     OUTPUT ("Bounding box corners:\n");
  363.     OUTPUT ("Upper right =  (%d, %d) \n", urx, ury);
  364.     OUTPUT ("Lower left  =  (%d, %d) \n", llx, lly);
  365.  
  366.     return OK;
  367.  
  368. } /* compound */
  369.  
  370.  
  371. Void
  372. end_compound __((void))
  373. {
  374.     OUTPUT ("End Compound Object.\n");
  375.  
  376. } /* end_compound */
  377.  
  378.  
  379. #define SOLID_LINE   0
  380. #define DASH_LINE    1
  381. #define DOTTED_LINE  2
  382.  
  383. #define DEFAULT_COLOR  (-1)
  384. #define BLACK    0
  385. #define BLUE     1
  386. #define GREEN    2
  387. #define CYAN     3
  388. #define RED      4
  389. #define MAGENTA  5
  390. #define YELLOW   6
  391. #define WHITE    7
  392.  
  393. #define DEFAULT_PEN  0
  394.  
  395. #define DEFAULT_FILL   0
  396. #define WHITE_FILL     1
  397. #define BLACK_FILL    21
  398.  
  399.  
  400. int
  401. common_fields
  402. #ifdef __STDC__
  403.   (FILE * fp)
  404. #else
  405.   (fp)
  406.     FILE * fp;
  407. #endif
  408. {
  409.     int line_style,
  410.         line_thickness,
  411.         color,
  412.         depth,
  413.         pen,
  414.         area_fill;
  415.  
  416.     float style_val;
  417.  
  418.     fscanf (fp, "%d", &line_style);
  419.     fscanf (fp, "%d", &line_thickness);
  420.     fscanf (fp, "%d", &color);
  421.     fscanf (fp, "%d", &depth);
  422.     fscanf (fp, "%d", &pen);
  423.     fscanf (fp, "%d", &area_fill);
  424.     fscanf (fp, "%f", &style_val);
  425.  
  426.     OUTPUT ("line style = ");
  427.     switch (line_style)
  428.     {
  429.         case SOLID_LINE :  OUTPUT ("solid");   break;
  430.         case DASH_LINE:    OUTPUT ("dash");    break;
  431.         case DOTTED_LINE:  OUTPUT ("dotted");  break;
  432.         default:
  433.                    OUTPUT ("INVALID");
  434.                    put_msg ("INVALID line style!");
  435.                    return FAIL;
  436.                    break;
  437.     }
  438.     OUTPUT ("\n");
  439.  
  440.     OUTPUT ("line thickness = %d pixels\n", line_thickness);
  441.  
  442.     OUTPUT ("color = ");
  443.     switch (color)
  444.     {
  445.         case DEFAULT_COLOR:  OUTPUT ("default");  break;
  446.         case BLACK:    OUTPUT ("black");  break;
  447.         case BLUE:     OUTPUT ("blue");  break;
  448.         case GREEN:    OUTPUT ("green");  break;
  449.         case CYAN:     OUTPUT ("cyan");  break;
  450.         case RED:      OUTPUT ("red");  break;
  451.         case MAGENTA:  OUTPUT ("magenta");  break;
  452.         case YELLOW:   OUTPUT ("yellow");  break;
  453.         case WHITE:    OUTPUT ("white");  break;
  454.         default:
  455.             OUTPUT ("INVALID");
  456.             put_msg ("INVALID color!");
  457.             return FAIL;
  458.             break;
  459.     }
  460.     OUTPUT ("\n");
  461.  
  462.     OUTPUT ("depth = layer %d\n", depth);
  463.  
  464.     OUTPUT ("pen = %d  (0 and -1 are the default values) \n", pen);
  465.  
  466.     OUTPUT ("area fill = ");
  467.     switch (area_fill)
  468.     {
  469.         case DEFAULT_FILL:  OUTPUT ("default");  break;
  470.         case WHITE_FILL:    OUTPUT ("white");  break;
  471.         case BLACK_FILL:    OUTPUT ("black");  break;
  472.         default:
  473.             if (area_fill > WHITE_FILL && area_fill < BLACK_FILL)
  474.             {
  475.                 OUTPUT ("grey, darkness = %d", area_fill);
  476.                 OUTPUT ("  (range : 1 to 21)");
  477.             }
  478.             else
  479.             {
  480.                 OUTPUT ("INVALID");
  481.                 put_msg ("INVALID area fill!");
  482.                 return FAIL;
  483.             }
  484.             break;
  485.     }
  486.     OUTPUT ("\n");
  487.  
  488.     OUTPUT ("style value = %.3f", style_val);
  489.     if (line_style == DASH_LINE)
  490.         OUTPUT (" = dash length");
  491.     else if (line_style == DOTTED_LINE)
  492.         OUTPUT (" = gap between dots");
  493.     else
  494.         OUTPUT (" : ignored");
  495.     OUTPUT ("\n");
  496.  
  497.     return OK;
  498. } /* common_fields */
  499.  
  500. int
  501. arrow
  502. #ifdef __STDC__
  503.   (FILE * fp)
  504. #else
  505.   (fp)
  506.     FILE * fp;
  507. #endif
  508. {
  509.     int at, as;
  510.     float athick, awidth, aht;
  511.  
  512.     fscanf (fp, "%d", &at);
  513.     fscanf (fp, "%d", &as);
  514.     fscanf (fp, "%f", &athick);
  515.     fscanf (fp, "%f", &awidth);
  516.     fscanf (fp, "%f", &aht);
  517.  
  518.     OUTPUT ("arrow_type = %d  (default is 0 or -1)\n", at);
  519.     OUTPUT ("arrow_style = %d  (default is 0 or -1)\n", as);
  520.     OUTPUT ("arrow_thickness = %.3f  (default is 0 or -1, I think)\n", athick);
  521.     OUTPUT ("arrow_width = %.3f\n", awidth);
  522.     OUTPUT ("arrow_height = %.3f\n", aht);
  523.  
  524.     return OK;
  525. } /* arrow */
  526.  
  527.  
  528. int
  529. points
  530. #ifdef __STDC__
  531.   (FILE * fp, int * p_npts)
  532. #else
  533.   (fp, p_npts)
  534.     FILE * fp;
  535.     int * p_npts;
  536. #endif
  537. {
  538.     int npts;
  539.  
  540.     for (npts = 0; ; npts++)
  541.     {
  542.         int x, y;
  543.  
  544.         if (fscanf (fp, "%d%d", &x, &y) != 2)
  545.         {
  546.             OUTPUT ("INCOMPLETE points line!\n");
  547.             put_msg ("INCOMPLETE points line!");
  548.             return FAIL;
  549.         }
  550.  
  551.         if (x == 9999)
  552.             break;
  553.  
  554.         OUTPUT ("    (%d, %d)\n", x, y);
  555.     }
  556.  
  557.     * p_npts = npts;  /* number of points */
  558.  
  559.     return OK;
  560.  
  561. } /* points */
  562.  
  563.  
  564. #define NO_ARROW  0
  565. #define ARROW     1
  566.  
  567. int
  568. arrow_check
  569. #ifdef __STDC__
  570.   (int fa, int ba)
  571. #else
  572.   (fa, ba)
  573.     int fa, ba;
  574. #endif
  575. {
  576.     OUTPUT ("forward arrow :  ");
  577.     switch (fa)
  578.     {
  579.         case ARROW:
  580.             OUTPUT ("yes");
  581.             break;
  582.         case NO_ARROW:
  583.             OUTPUT ("no");
  584.             break;
  585.         default:
  586.             OUTPUT ("INVALID  (fa = %d)  !", fa);
  587.             put_msg ("INVALID forward arrow code!");
  588.             return FAIL;
  589.             break;
  590.     }
  591.     OUTPUT ("\n");
  592.  
  593.     OUTPUT ("backward arrow :  ");
  594.     switch (ba)
  595.     {
  596.         case ARROW:
  597.             OUTPUT ("yes");
  598.             break;
  599.         case NO_ARROW:
  600.             OUTPUT ("no");
  601.             break;
  602.         default:
  603.             OUTPUT ("INVALID  (ba = %d)  !", ba);
  604.             put_msg ("INVALID backward arrow code!");
  605.             return FAIL;
  606.             break;
  607.     }
  608.     OUTPUT ("\n");
  609.  
  610.     return OK;
  611.  
  612. }  /* arrow_check */
  613.  
  614.  
  615. #define T_POLYLINE  1
  616. #define T_BOX       2
  617. #define T_POLYGON   3
  618. #define T_ARC_BOX   4
  619. #define T_EPS_BOX   5
  620.  
  621. #define EPS_UPRIGHT  0
  622. #define EPS_FLIPPED  1
  623.  
  624. int
  625. polyline
  626. #ifdef __STDC__
  627.   (FILE * fp)
  628. #else
  629.   (fp)
  630.     FILE * fp;
  631. #endif
  632. {
  633.     int    sub_type;
  634.     int    radius;
  635.     int    fa,
  636.         ba;
  637.     int    flipped;
  638.     char    epsfile[100 + 1];
  639.     int     npts;
  640.  
  641.     OUTPUT ("Polyline Object:\n");
  642.  
  643.     fscanf (fp, "%d", &sub_type);
  644.  
  645.     OUTPUT ("sub_type = ");
  646.     switch (sub_type)
  647.     {
  648.         case T_POLYLINE:  OUTPUT ("polyline");  break;
  649.         case T_BOX:       OUTPUT ("box");  break;
  650.         case T_POLYGON:   OUTPUT ("polygon");  break;
  651.         case T_ARC_BOX:   OUTPUT ("arc_box");  break;
  652.         case T_EPS_BOX:   OUTPUT ("eps_box");  break;
  653.         default:
  654.             OUTPUT ("INVALID");
  655.             put_msg ("INVALID polyline subtype!");
  656.             return FAIL;
  657.             break;
  658.     }
  659.     OUTPUT ("\n");
  660.  
  661.     if (common_fields (fp) == FAIL)
  662.         return FAIL;
  663.  
  664.     fscanf (fp, "%d", &radius);
  665.     OUTPUT ("radius = %d\n", radius);
  666.  
  667.     fscanf (fp, "%d", &fa);
  668.     fscanf (fp, "%d", &ba);
  669.  
  670.     if (arrow_check (fa, ba) == FAIL)
  671.         return FAIL;
  672.  
  673.     if (fa == ARROW)
  674.     {
  675.       OUTPUT ("forward arrow has:\n");
  676.       if (arrow (fp) == FAIL)
  677.         return FAIL;
  678.     }
  679.  
  680.     if (ba == ARROW)
  681.     {
  682.       OUTPUT ("backward arrow has:\n");
  683.       if (arrow (fp) == FAIL)
  684.         return FAIL;
  685.     }
  686.  
  687.     /* Transfig Manual and xfig's FORMAT2.1 for version 2.1.8 */
  688.     /* disagree with transfig's read.c and xfig/Example/logo.fig; */
  689.     /* I go with the latter, until proven otherwise. */
  690.  
  691.     if (sub_type == T_EPS_BOX)
  692.     {
  693.         int ch;
  694.  
  695.         fscanf (fp, "%d", &flipped);
  696.  
  697.         fscanf (fp, "%100s", epsfile);
  698.  
  699.         /* skip any remaining characters in EPS filename */
  700.         while (! isspace (ch = getc(fp)))
  701.             ;
  702.  
  703.         OUTPUT ("EPS orientation = ");
  704.         switch (flipped)
  705.         {
  706.             case EPS_UPRIGHT:
  707.                 OUTPUT ("upright");
  708.                 break;
  709.             case EPS_FLIPPED:
  710.                 OUTPUT ("flipped");
  711.                 break;
  712.             default:
  713.                 OUTPUT ("INVALID");
  714.                 put_msg ("INVALID EPS orientation!");
  715.                 return FAIL;
  716.                 break;
  717.         }
  718.         OUTPUT ("\n");
  719.         OUTPUT ("EPS filename = `%s'\n", epsfile);
  720.     }
  721.  
  722.     OUTPUT ("Corner points:\n");
  723.     if (points (fp, &npts) == FAIL)
  724.         return FAIL;
  725.  
  726.     return OK;
  727.  
  728. } /* polyline */
  729.  
  730.  
  731. #define T_OPEN_NORMAL      0
  732. #define T_CLOSED_NORMAL    1
  733. #define T_OPEN_INTERPOLATED    2
  734. #define T_CLOSED_INTERPOLATED  3
  735.  
  736. int
  737. spline
  738. #ifdef __STDC__
  739.   (FILE * fp)
  740. #else
  741.   (fp)
  742.     FILE * fp;
  743. #endif
  744. {
  745.     int  sub_type;
  746.     int  fa,
  747.          ba;
  748.     int  nkeys;
  749.  
  750.     OUTPUT ("Spline Object:\n");
  751.  
  752.     fscanf (fp, "%d", &sub_type);
  753.  
  754.     switch (sub_type)
  755.     {
  756.         case T_OPEN_NORMAL:
  757.             OUTPUT ("open B-spline");
  758.             break;
  759.         case T_CLOSED_NORMAL:
  760.             OUTPUT ("closed B-spline");
  761.             break;
  762.         case T_OPEN_INTERPOLATED:
  763.             OUTPUT ("open interpolated spline");
  764.             break;
  765.         case T_CLOSED_INTERPOLATED:
  766.             OUTPUT ("closed interpolated spline");
  767.             break;
  768.         default:
  769.             OUTPUT ("INVALID spline sub_type");
  770.             put_msg ("INVALID spline sub_type!");
  771.             return FAIL;
  772.             break;
  773.     }
  774.     OUTPUT ("\n");
  775.  
  776.     if (common_fields (fp) == FAIL)
  777.         return FAIL;
  778.  
  779.     fscanf (fp, "%d", &fa);
  780.     fscanf (fp, "%d", &ba);
  781.  
  782.     if (arrow_check (fa, ba) == FAIL)
  783.         return FAIL;
  784.  
  785.     if (fa == ARROW)
  786.     {
  787.       OUTPUT ("forward arrow has:\n");
  788.       if (arrow (fp) == FAIL)
  789.         return FAIL;
  790.     }
  791.  
  792.     if (ba == ARROW)
  793.     {
  794.       OUTPUT ("backward arrow has:\n");
  795.       if (arrow (fp) == FAIL)
  796.         return FAIL;
  797.     }
  798.  
  799.     OUTPUT ("Key points:\n");
  800.     if (points (fp, &nkeys) == FAIL)
  801.         return FAIL;
  802.  
  803.     switch (sub_type)
  804.     {
  805.         case T_OPEN_INTERPOLATED:
  806.         case T_CLOSED_INTERPOLATED:
  807.         {
  808.             int i;
  809.             OUTPUT ("Control points:\n");
  810.             for (i=0; i < nkeys; i++)
  811.             {
  812.                 int j;
  813.                 /* two control points per key point */
  814.                 for (j=0; j < 2; j++)
  815.                 {
  816.                     float    x, y;
  817.                     fscanf (fp, "%f", &x);
  818.                     fscanf (fp, "%f", &y);
  819.                     OUTPUT ("(%.3f, %.3f)  ", x, y);
  820.                 }
  821.                 OUTPUT ("\n");
  822.             }
  823.         }
  824.     }
  825.  
  826.     return OK;
  827.  
  828. } /* spline */
  829.  
  830.  
  831. #define T_ELLIPSE_BY_RAD  1
  832. #define T_ELLIPSE_BY_DIA  2
  833. #define T_CIRCLE_BY_RAD   3
  834. #define T_CIRCLE_BY_DIA   4
  835.  
  836. int
  837. ellipse
  838. #ifdef __STDC__
  839.   (FILE * fp)
  840. #else
  841.   (fp)
  842.     FILE * fp;
  843. #endif
  844. {
  845.     int    sub_type;
  846.     int    direction;
  847.     float  angle;
  848.     int    cx, cy,
  849.            rx, ry,
  850.            sx, sy,
  851.            ex, ey;
  852.  
  853.     OUTPUT ("Ellipse Object:\n");
  854.  
  855.     fscanf (fp, "%d", &sub_type);
  856.  
  857.     switch (sub_type)
  858.     {
  859.         case T_ELLIPSE_BY_RAD:
  860.             OUTPUT ("ellipse by radius");
  861.             break;
  862.         case T_ELLIPSE_BY_DIA:
  863.             OUTPUT ("ellipse by diameter");
  864.             break;
  865.         case T_CIRCLE_BY_RAD:
  866.             OUTPUT ("circle by radius");
  867.             break;
  868.         case T_CIRCLE_BY_DIA:
  869.             OUTPUT ("circle by diameter");
  870.             break;
  871.         default:
  872.             OUTPUT ("INVALID ellipse sub_type");
  873.             put_msg ("INVALID ellipse sub_type!");
  874.             return FAIL;
  875.             break;
  876.     }
  877.     OUTPUT ("\n");
  878.  
  879.     if (common_fields (fp) == FAIL)
  880.         return FAIL;
  881.  
  882.     fscanf (fp, "%d", &direction);
  883.     OUTPUT ("direction = %d  (should be fixed at 1) \n", direction);
  884.  
  885.     fscanf (fp, "%f", &angle);
  886.     OUTPUT ("angle = %.3f radians\n", angle);
  887.  
  888.     fscanf (fp, "%d", &cx);
  889.     fscanf (fp, "%d", &cy);
  890.     OUTPUT ("centre = (%d,%d) \n", cx, cy);
  891.  
  892.     fscanf (fp, "%d", &rx);
  893.     fscanf (fp, "%d", &ry);
  894.     OUTPUT ("radii = (%d,%d) \n", rx, ry);
  895.  
  896.     fscanf (fp, "%d", &sx);
  897.     fscanf (fp, "%d", &sy);
  898.     OUTPUT ("(Fig internal) start = (%d,%d) \n", sx, sy);
  899.  
  900.     fscanf (fp, "%d", &ex);
  901.     fscanf (fp, "%d", &ey);
  902.     OUTPUT ("(Fig internal) end = (%d,%d) \n", ex, ey);
  903.  
  904.     return OK;
  905.  
  906. } /* ellipse */
  907.  
  908.  
  909. #define T_3_POINT_ARC  1
  910.  
  911. #define CLOCKWISE  0
  912. #define COUNTER    1
  913.  
  914. int
  915. arc
  916. #ifdef __STDC__
  917.   (FILE * fp)
  918. #else
  919.   (fp)
  920.     FILE * fp;
  921. #endif
  922. {
  923.     int    sub_type;
  924.     int    direction;
  925.     int    fa, ba;
  926.     float  cx, cy;
  927.     int    x1, y1,
  928.            x2, y2,
  929.            x3, y3;
  930.  
  931.     OUTPUT ("Arc Object:\n");
  932.  
  933.     fscanf (fp, "%d", &sub_type);
  934.  
  935.     if (sub_type == T_3_POINT_ARC)
  936.         OUTPUT ("three point arc\n");
  937.     else
  938.     {
  939.         OUTPUT ("INVALID arc sub_type %d\n", sub_type);
  940.         put_msg ("INVALID arc sub_type!");
  941.         return FAIL;
  942.     }
  943.  
  944.     if (common_fields (fp) == FAIL)
  945.         return FAIL;
  946.  
  947.     fscanf (fp, "%d", &direction);
  948.     OUTPUT ("direction = ");
  949.     switch (direction)
  950.     {
  951.         case CLOCKWISE:
  952.             OUTPUT ("clockwise");
  953.             break;
  954.         case COUNTER:
  955.             OUTPUT ("counter clockwise");
  956.             break;
  957.         default:
  958.             OUTPUT ("INVALID (%d)", direction);
  959.             put_msg ("INVALID direction!");
  960.             return FAIL;
  961.             break;
  962.     }
  963.     OUTPUT ("\n");
  964.  
  965.     fscanf (fp, "%d", &fa);
  966.     fscanf (fp, "%d", &ba);
  967.  
  968.     if (arrow_check (fa, ba) == FAIL)
  969.         return FAIL;
  970.  
  971.     fscanf (fp, "%f", &cx);
  972.     fscanf (fp, "%f", &cy);
  973.     OUTPUT ("centre = (%.3f, %.3f)\n", cx, cy);
  974.  
  975.     fscanf (fp, "%d", &x1);
  976.     fscanf (fp, "%d", &y1);
  977.     OUTPUT ("point 1 = (%d, %d)\n", x1, y1);
  978.  
  979.     fscanf (fp, "%d", &x2);
  980.     fscanf (fp, "%d", &y2);
  981.     OUTPUT ("point 2 = (%d, %d)\n", x2, y2);
  982.  
  983.     fscanf (fp, "%d", &x3);
  984.     fscanf (fp, "%d", &y3);
  985.     OUTPUT ("point 3 = (%d, %d)\n", x3, y3);
  986.  
  987.     if (fa == ARROW)
  988.     {
  989.       OUTPUT ("forward arrow has:\n");
  990.       if (arrow (fp) == FAIL)
  991.         return FAIL;
  992.     }
  993.  
  994.     if (ba == ARROW)
  995.     {
  996.       OUTPUT ("backward arrow has:\n");
  997.       if (arrow (fp) == FAIL)
  998.         return FAIL;
  999.     }
  1000.  
  1001.     return OK;
  1002.  
  1003. } /* arc */
  1004.  
  1005.  
  1006. #define T_LEFT_JUSTIFIED    0
  1007. #define T_CENTER_JUSTIFIED  1
  1008. #define T_RIGHT_JUSTIFIED   2
  1009.  
  1010. #define DEFAULT_FONT_0  0
  1011. #define DEFAULT_FONT_1  (-1)
  1012.  
  1013. #define ROMAN       1
  1014. #define BOLD        2
  1015. #define ITALICS     3
  1016. #define MODERN      4
  1017. #define TYPEWRITER  5
  1018.  
  1019. #define NO_TEXT       0
  1020. #define RIGID_TEXT    1
  1021. #define SPECIAL_TEXT  2
  1022. #define PSFONT_TEXT   4
  1023. #define HIDDEN_TEXT   8
  1024.  
  1025. #define TR       1
  1026. #define TI       2
  1027. #define TB       3
  1028. #define TBI      4
  1029. #define AG       5
  1030. #define AGBO     6
  1031. #define AGD      7
  1032. #define AGDO     8
  1033. #define BKL      9
  1034. #define BKLI    10
  1035. #define BKD     11
  1036. #define BKDI    12
  1037. #define COUR    13
  1038. #define COURO   14
  1039. #define COURB   15
  1040. #define COURBI  16
  1041. #define HV      17
  1042. #define HVO     18
  1043. #define HVB     19
  1044. #define HVBO    20
  1045. #define HVN     21
  1046. #define HVNO    22
  1047. #define HVNB    23
  1048. #define HVNBO   24
  1049. #define NCR     25
  1050. #define NCI     26
  1051. #define NCB     27
  1052. #define NCBI    28
  1053. #define PLR     29
  1054. #define PLI     30
  1055. #define PLB     31
  1056. #define PLBI    32
  1057. #define SYMBOL  33
  1058. #define ZCMI    34
  1059. #define ZDING   35
  1060.  
  1061. int
  1062. text
  1063. #ifdef __STDC__
  1064.   (FILE * fp)
  1065. #else
  1066.   (fp)
  1067.     FILE * fp;
  1068. #endif
  1069. {
  1070.     int    sub_type;
  1071.     int    font;
  1072.     float  size;
  1073.     int    pen,
  1074.            color,
  1075.            depth;
  1076.     float  angle;
  1077.     int    text_flags;
  1078.     float  height, length;
  1079.     int    x, y;
  1080.  
  1081.     char     text[80],    /* WARNING:  THIS MAY NOT BE BIG ENOUGH! */
  1082.         junk[2];
  1083.  
  1084.     OUTPUT ("Text Object:\n");
  1085.  
  1086.     fscanf (fp, "%d", &sub_type);
  1087.     OUTPUT ("sub_type = ");
  1088.     switch (sub_type)
  1089.     {
  1090.         case T_LEFT_JUSTIFIED:
  1091.             OUTPUT ("left justified");
  1092.             break;
  1093.         case T_CENTER_JUSTIFIED:
  1094.             OUTPUT ("centre justified");
  1095.             break;
  1096.         case T_RIGHT_JUSTIFIED:
  1097.             OUTPUT ("right justified");
  1098.             break;
  1099.         default:
  1100.             OUTPUT ("INVALID text sub_type = %d", sub_type);
  1101.             put_msg ("INVALID text sub_type!");
  1102.             return FAIL;
  1103.             break;
  1104.     }
  1105.     OUTPUT ("\n");
  1106.  
  1107.     fscanf (fp, "%d", &font);
  1108.  
  1109.     OUTPUT ("font = %d  (this code is to be interpreted below)\n", font);
  1110.  
  1111.     fscanf (fp, "%f", &size);
  1112.     OUTPUT ("font size = %.3f\n", size);
  1113.  
  1114.     fscanf (fp, "%d", &pen);
  1115.     OUTPUT ("pen = %d  (should be default = 0 or -1) \n", pen);
  1116.  
  1117.     fscanf (fp, "%d", &color);
  1118.     OUTPUT ("color = %d  (should be default = 0 or -1) \n", color);
  1119.  
  1120.     fscanf (fp, "%d", &depth);
  1121.     OUTPUT ("depth = level %d\n", depth);
  1122.  
  1123.     fscanf (fp, "%f", &angle);
  1124.     OUTPUT ("angle = %.3f radians\n", angle);
  1125.  
  1126.     fscanf (fp, "%d", &text_flags);
  1127.     OUTPUT ("text flags:  ");
  1128.     if (text_flags == NO_TEXT)
  1129.         OUTPUT ("none");
  1130.     else
  1131.     {
  1132.         if (text_flags & RIGID_TEXT)
  1133.             OUTPUT ("rigid ");
  1134.         if (text_flags & SPECIAL_TEXT)
  1135.             OUTPUT ("special ");
  1136.         if (text_flags & PSFONT_TEXT)
  1137.             OUTPUT ("PostScript ");
  1138.         if (text_flags & HIDDEN_TEXT)
  1139.             OUTPUT ("hidden ");
  1140.     }
  1141.     OUTPUT ("\n");
  1142.  
  1143.     OUTPUT ("font name = ");
  1144.     if (text_flags & PSFONT_TEXT)
  1145.     {
  1146.         switch (font)
  1147.         {
  1148.             case DEFAULT_FONT_0:
  1149.             case DEFAULT_FONT_1:
  1150.                 OUTPUT ("default");
  1151.                 break;
  1152.             case TR:
  1153.                 OUTPUT ("Times-Roman");
  1154.                 break;
  1155.             case TI:
  1156.                 OUTPUT ("Times-Italic");
  1157.                 break;
  1158.             case TB:
  1159.                 OUTPUT ("Times-Bold");
  1160.                 break;
  1161.             case TBI:
  1162.                 OUTPUT ("Times-Bold-Italic");
  1163.                 break;
  1164.             case AG:
  1165.                 OUTPUT ("AvantGarde");
  1166.                 break;
  1167.             case AGBO:
  1168.                 OUTPUT ("AvantGarde-BookOblique");
  1169.                 break;
  1170.             case AGD:
  1171.                 OUTPUT ("AvantGarde-Demi");
  1172.                 break;
  1173.             case AGDO:
  1174.                 OUTPUT ("AvantGarde-DemiOblique");
  1175.                 break;
  1176.             case BKL:
  1177.                 OUTPUT ("Bookman-Light");
  1178.                 break;
  1179.             case BKLI:
  1180.                 OUTPUT ("Bookman-LightItalic");
  1181.                 break;
  1182.             case BKD:
  1183.                 OUTPUT ("Bookman-Demi");
  1184.                 break;
  1185.             case BKDI:
  1186.                 OUTPUT ("Bookman-DemiItalic");
  1187.                 break;
  1188.             case COUR:
  1189.                 OUTPUT ("Courier");
  1190.                 break;
  1191.             case COURO:
  1192.                 OUTPUT ("Courier-Oblique");
  1193.                 break;
  1194.             case COURB:
  1195.                 OUTPUT ("Courier-Bold");
  1196.                 break;
  1197.             case COURBI:
  1198.                 OUTPUT ("Courier-BoldItalic");
  1199.                 break;
  1200.             case HV:
  1201.                 OUTPUT ("Helvetica");
  1202.                 break;
  1203.             case HVO:
  1204.                 OUTPUT ("Helvetica-Oblique");
  1205.                 break;
  1206.             case HVB:
  1207.                 OUTPUT ("Helvetica-Bold");
  1208.                 break;
  1209.             case HVBO:
  1210.                 OUTPUT ("Helvetica-BoldOblique");
  1211.                 break;
  1212.             case HVN:
  1213.                 OUTPUT ("Helvetica-Narrow");
  1214.                 break;
  1215.             case HVNO:
  1216.                 OUTPUT ("Helvetica-Narrow-Oblique");
  1217.                 break;
  1218.             case HVNB:
  1219.                 OUTPUT ("Helvetica-Narrow-Bold");
  1220.                 break;
  1221.             case HVNBO:
  1222.                 OUTPUT ("Helvetica-Narrow-BoldOblique");
  1223.                 break;
  1224.             case NCR:
  1225.                 OUTPUT ("NewCenturySchlbk-Roman");
  1226.                 break;
  1227.             case NCI:
  1228.                 OUTPUT ("NewCenturySchlbk-Italic");
  1229.                 break;
  1230.             case NCB:
  1231.                 OUTPUT ("NewCenturySchlbk-Bold");
  1232.                 break;
  1233.             case NCBI:
  1234.                 OUTPUT ("NewCenturySchlbk-BoldItalic");
  1235.                 break;
  1236.             case PLR:
  1237.                 OUTPUT ("Palatino-Roman");
  1238.                 break;
  1239.             case PLI:
  1240.                 OUTPUT ("Palatino-Italic");
  1241.                 break;
  1242.             case PLB:
  1243.                 OUTPUT ("Palatino-Bold");
  1244.                 break;
  1245.             case PLBI:
  1246.                 OUTPUT ("Palatino-BoldItalic");
  1247.                 break;
  1248.             case SYMBOL:
  1249.                 OUTPUT ("Symbol");
  1250.                 break;
  1251.             case ZCMI:
  1252.                 OUTPUT ("ZapfChancery-MediumItalic");
  1253.                 break;
  1254.             case ZDING:
  1255.                 OUTPUT ("ZapfDingbats");
  1256.                 break;
  1257.             default:
  1258.                 OUTPUT ("INVALID PostScript font = %d\n", font);
  1259.                 put_msg ("INVALID PostScript font!");
  1260.                 return FAIL;
  1261.                 break;
  1262.         }
  1263.     }
  1264.     else
  1265.     {
  1266.         switch (font)
  1267.         {
  1268.             case DEFAULT_FONT_0:
  1269.             case DEFAULT_FONT_1:
  1270.                 OUTPUT ("default");
  1271.                 break;
  1272.             case ROMAN:
  1273.                 OUTPUT ("Roman");
  1274.                 break;
  1275.             case BOLD:
  1276.                 OUTPUT ("Bold");
  1277.                 break;
  1278.             case ITALICS:
  1279.                 OUTPUT ("Italics");
  1280.                 break;
  1281.             case MODERN:
  1282.                 OUTPUT ("Modern (sans serif)");
  1283.                 break;
  1284.             case TYPEWRITER:
  1285.                 OUTPUT ("Typewriter");
  1286.                 break;
  1287.             default:
  1288.                 OUTPUT ("INVALID Fig font = %d", font);
  1289.                 put_msg ("INVALID Fig font!");
  1290.                 return FAIL;
  1291.                 break;
  1292.         }
  1293.     }
  1294.     OUTPUT ("\n");
  1295.  
  1296.     fscanf (fp, "%f", &height);
  1297.     OUTPUT ("height = %.3f pixels\n", height);
  1298.  
  1299.     fscanf (fp, "%f", &length);
  1300.     OUTPUT ("length = %.3f pixels\n", length);
  1301.  
  1302.     fscanf (fp, "%d", &x);
  1303.     fscanf (fp, "%d", &y);
  1304.     OUTPUT ("text location = (%d, %d) \n", x, y);
  1305.  
  1306.     fscanf (fp, "%[^\1]%[\1]", text, junk);
  1307.     OUTPUT ("text = `%s'\n", text);
  1308.  
  1309.     return OK;
  1310.  
  1311. } /* text */
  1312.  
  1313.  
  1314. /* end of fig2eng 0.4 of Mon 27 June 1994 */
  1315.